/*
 * 文件名：SharedPreferenceService.java
 * 版权：(C)版权所有2013-2013 com.zilla
 * 描述：SharedPreference管理类
 * 修改人：ze.chen
 * 修改时间：2013-6-4 上午9:36:46
 */
package com.zilla.android.zillacore.libzilla.file;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;

/**
 * 配置文件管理器<br>
 * 配置文件管理器,简单封装SharedPreference,提供直接的读写方法,get,put
 *
 * @author ze.chen
 * @version 1.0
 * @date 2013-6-4 下午1:54:54
 */

@SuppressLint("CommitPrefEdits")
public class SharedPreferenceService {

    SharedPreferences sp;
    SharedPreferences.Editor editor;
    private Context mContext = null;

    private static SharedPreferenceService manager = null;

    private SharedPreferenceService(Context context) {
        mContext = context.getApplicationContext();
        sp = mContext.getSharedPreferences("sys_setting", 0);
        editor = sp.edit();
    }

    public static SharedPreferenceService getInstance(Context context) {
        if (manager == null) {
            manager = new SharedPreferenceService(context);
        }
        return manager;
    }

    public static SharedPreferenceService getInstance() {
        return manager;
    }

    public void put(String key, String value) {
        editor.putString(key, value);
        editor.commit();
    }

    public void put(String key, int value) {
        editor.putInt(key, value);
        editor.commit();
    }

    public void put(String key, long value) {
        editor.putLong(key, value);
        editor.commit();
    }

    public void put(String key, boolean value) {
        editor.putBoolean(key, value);
        editor.commit();
    }

    public String get(String key, String defValue) {
        return sp.getString(key, defValue);
    }

    public int get(String key, int defValue) {
        return sp.getInt(key, defValue);
    }

    public long get(String key, long defValue) {
        return sp.getLong(key, defValue);
    }

    public boolean get(String key, boolean defValue) {
        return sp.getBoolean(key, defValue);
    }
}
